<!-- 职位管理 -->
<template>
  <div id="manager-recruiter">
    <el-container style="height: 100vh; border: 1px">
      <el-header>
        <HeaderBar></HeaderBar>
      </el-header>
      <el-container style="flex: 1; display: flex;">
        <!-- 左侧栏 -->
        <el-aside :width="sidebarWidth" style="transition: width 0.3s ease;">
          <Sidebar @sidebar-toggle="handleSidebarToggle"></Sidebar>
        </el-aside>
        <!-- 主体内容区 -->
        <el-main :style="{
          marginLeft: '0',
          transition: 'margin-left 0.3s ease',
          width: `calc(100% - ${sidebarWidth})`
        }">
          <!-- <h2 style="font-size: 20px;font-weight: blod;">职位管理</h2> -->
          <el-row class="search">
            <input class="relative" v-model="searchKeyword" type="text" placeholder="搜索职位...">
            <!-- <el-button class="button" @click="handleSearch" icon="el-icon-search">搜索</el-button> -->
          </el-row>
          <!-- 职位信息列表 -->
          <div class="table-scroll-container">
            <el-table :data="tableData" class="position-table" style="width: 100%;">
              <!-- 职位名称 -->
              <el-table-column prop="" label="职位信息" width="180">
                <template slot-scope="scope">
                  <span>{{ scope.row.positionName }}</span>
                </template>
              </el-table-column>
              <el-table-column prop="" label="发布方" width="150">
                <template slot-scope="scope">
                  <span>{{ scope.row.userName }}</span>
                </template>
              </el-table-column>
              <el-table-column prop="" label="联系电话" width="180">
                <template slot-scope="scope">
                  <span>{{ scope.row.phone }}</span>
                </template>
              </el-table-column>
              <!-- 薪资 -->
              <el-table-column  label="薪资" width="150">
                <template slot-scope="scope">
                  <span>{{ scope.row.lowestSalaryMonth }}-{{ scope.row.highestSalaryMonth }}</span>
                </template>
              </el-table-column>
              <!-- 发布时间 -->
              <el-table-column  label="发布时间" width="200">
                 <template slot-scope="scope">
                  <span>{{formatDate(scope.row.startAt)}}-{{ formatDate(scope.row.endAt) }}</span>
                </template>
              </el-table-column>
              <!-- 详细信息 -->
              <el-table-column label="详细信息" width="100">
                <template slot-scope="scope">
                  <el-button size="mini" type="primary" icon="el-icon-info" plain
                    @click="lookPosMessage(scope.row)"></el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page="currentPage" :page-sizes="[5, 10, 20]" :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"  :total="totalCount">
          </el-pagination>
        </el-main>
      </el-container>
    </el-container>
      <positionMessage :visible.sync="positionMessageVisible" :position="currentPosition"></positionMessage>
  </div>
</template>
<script>
import Sidebar from "@/components/ManagerSidebar.vue";
import HeaderBar from "@/components/ManagerHeaderBar.vue";
import positionMessage from "./components/positionMessage.vue";
import { getPositions } from "@/util/manager_api/position";
export default {
  components: {
    Sidebar,
    HeaderBar,
    positionMessage,
  },
  data() {
    return {
      tableData:[],
      searchKeyword:'',
      currentPage: 1,
      pageSize: 5,
      totalCount: 0,
      isSidebarCollapsed: false,
      currentPosition:{},
      positionMessageVisible:false,
    };
  },
  computed: {
    sidebarWidth() {
      return this.isSidebarCollapsed ? '30px' : '200px';
    }
  },
  created() {
    this.fetchPositions();
  },
  watch: {
    searchKeyword() {
      this.fetchPositions();
    }
  },
  methods: {
    async fetchPositions() {
      try {
        const params = {
          page: this.currentPage,
          size: this.pageSize,
          content: this.searchKeyword 
        };
      const response = await getPositions(params);
      console.log('postion:',response.data.data)
        this.tableData = response.data.data.respList;
        this.totalCount = response.data.data.total || 0;
      } catch (error) {
         console.error('获取公司列表失败:', error);
      }
    },
    lookPosMessage(position) {
      // console.log(position)
      this.currentPosition = position;
      this.positionMessageVisible = true;
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.fetchPositions();
    },
    handleCurrentChange(val){
      this.currentPage = val;
      this.fetchPositions();
    },
    formatDate(timestamp) {
      if (!timestamp) return '';
      const date = new Date(timestamp);
      return date.toLocaleDateString() + ' ' + date.toTimeString().substr(0,0); // 显示到秒
    },
    handleSidebarToggle(isCollapsed) {
      this.isSidebarCollapsed = isCollapsed;
    },
  }
};
</script>
<style scoped>
/* 头部信息 */
.el-header {
  height: 60px;
  width: 100%;
}

/* 侧边栏 */
.el-aside {
  background-color: white;
  color: #333;
  text-align: center;
  line-height: 200px;
  width: 200px;
}

/* 主体内容 */
.el-main {
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  background-color: #f8f9fa;
  color: #333;
  font-size: 20px;
  padding: 20px;
}

/* 搜索、筛选区域 */
.search {
  background-color: white;
  display: flex;
  align-items: center;
  padding: 10px 16px;
  border-radius: 4px;
  margin-bottom: 15px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.search>* {
  margin-right: 10px;
}

.search>*:last-child {
  margin-right: 0;
}

.relative {
  border-radius: 4px;
  border: 1px solid #dcdfe6;
  height: 32px;
  flex: 1;
  padding: 0 12px;
  font-size: 14px;
  transition: border-color 0.2s;
}

.relative:focus {
  outline: none;
  border-color: #409eff;
}

.button {
  border-radius: 4px;
  background-color: #409eff;
  border: none;
  color: white;
  height: 32px;
  padding: 0 16px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 14px;
  display: flex;
  align-items: center;
}

.button:hover {
  background-color: #66b1ff;
  transform: translateY(-1px);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.button:active {
  transform: translateY(0);
  box-shadow: none;
}

/* 表格滚动容器 */
.table-scroll-container {
  height: 370px;
  overflow-y: auto;
  margin-bottom: 15px;
  background-color: white;
  border-radius: 5px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* 职位表格样式 */
.position-table {
  width: 100%;
  border-collapse: collapse;
}

.position-table thead th {
  background-color: #f8f9fa;
  font-weight: 500;
  padding: 12px 15px;
  border-bottom: 1px solid #ebeef5;
  position: sticky;
  top: 0;
  z-index: 10;
}

.position-table tbody tr {
  border-bottom: 1px solid #ebeef5;
}

.position-table tbody tr:last-child {
  border-bottom: none;
}

.position-table tbody tr:hover {
  background-color: #f5f7fa;
}
</style>